package com.terren.spider.core.html.scheme.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.terren.spider.entity.core.Entry;

import us.codecraft.webmagic.Page;

public class CheyisouScheme extends BasicCustomScheme{
	@Override
	public boolean useAbuyunProxy() {
		
		return true;
	}
	 /**
	  * 抓分页
	  */
	@Override
	public Set<String> findHelpPaginationUrl(Page page, Entry entry) {
		List<String> pgList = new ArrayList<String>();// 存放分页list
		boolean flag = false;
		String nextUrl = page.getHtml().$(".next-on","href").toString();
		String prevUrl = page.getHtml().$(".preview-on","href").toString();
		if (!"".equals(nextUrl)&&nextUrl!=null) {//抓【下一页】链接
			pgList.add(nextUrl);
		}
		if ((!"".equals(prevUrl)&&prevUrl!=null)||(!"".equals(nextUrl)&&nextUrl!=null)) {//包含上一页或者下一页链接
			flag = true;
		}
		if (!flag) {//没有上一页链接也没有下一页链接 ，取全部
			pgList = page.getHtml().xpath("//div[@class='pagination']").links().all();// 存放分页list
		}
		Set<String> resultSet = new HashSet<>();
		resultSet.addAll(pgList);
		return resultSet;
	}
}
